
export function getTimeNow() {
  const myDate = new Date()
  const year = myDate.getFullYear() // 获取系统的年；
  let nowMonth = myDate.getMonth() + 1
  let strDate = myDate.getDate() // 获取系统日，
  let hour = myDate.getHours() // 获取系统时，
  let minute = myDate.getMinutes() // 分
  let second = myDate.getSeconds() // 秒
  nowMonth = nowMonth < 10 ? '0' + nowMonth : nowMonth
  strDate = strDate < 10 ? '0' + strDate : strDate
  hour = hour < 10 ? '0' + hour : hour
  minute = minute < 10 ? '0' + minute : minute
  second = second < 10 ? '0' + second : second
  return year + '-' + nowMonth + '-' + strDate + ' ' + hour + ':' + minute + ':' + second
}
// 间隔天数
export function TimeDifference(time1, time2) {
  // 定义两个变量time1,time2分别保存开始和结束时间
  var stime = new Date(time1.substring(0, 10)).getTime()
  var etime = new Date(time2.substring(0, 10)).getTime()
  var usedTime = etime - stime // 两个时间戳相差的毫秒数
  return Math.floor(usedTime / (24 * 3600 * 1000))
}

// 间隔秒数
export function TimeDifferenceSeconds(time1, time2) {
  // 定义两个变量time1,time2分别保存开始和结束时间
  var stime = new Date(time1).getTime()
  var etime = new Date(time2).getTime()
  var usedTime = etime - stime // 两个时间戳相差的毫秒数
  return Math.floor(usedTime / 1000)
}
export function formatTimeMills(timeMills) {
  var date = new Date(timeMills)
  var timeStr = date.getFullYear() + '-'
  if (date.getMonth() < 9) { // 月份从0开始的
    timeStr += '0'
  }
  timeStr += date.getMonth() + 1 + '-'
  timeStr += date.getDate() < 10 ? ('0' + date.getDate()) : date.getDate()
  timeStr += ' '
  timeStr += date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()
  timeStr += ':'
  timeStr += date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes()
  timeStr += ':'
  timeStr += date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds()
  return timeStr
}
// 获取设定时间与隔离结束时间的差值
function BetweenNow(time) {
  const myDate = new Date()
  return TimeDifferenceSeconds(myDate, time)
}

export function getCountTime(start) {
  const endDate = new Date(start)
  endDate.setDate(endDate.getDate() + 14)
  let seconds = BetweenNow(endDate)
  if (seconds === 0) return 0
  let rs = ''
  const days = Math.floor(seconds / 86400)
  seconds = seconds % 86400
  const hours = Math.floor(seconds / 3600)
  seconds = seconds % 3600
  const minutes = Math.floor(seconds / 60)
  seconds = seconds % 60
  if (days > 0) rs += days + '天'
  rs += hours + '小时'
  rs += minutes + '分钟'
  rs += seconds + '秒'
  return rs
}

export function getEndTime(time) {
  const start = new Date(time)
  start.setDate(start.getDate() + 14)
  return formatTimeMills(start)
}
